﻿using System;
using System.Collections.Generic;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCA.UI.Utils;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Reflection;
using Baosight.ZNH.ZMCA.UI.Model;


namespace Baosight.ZNH.ZMCA.UI
{


    public partial class ZMCA15 : EFView
    {
        ZMCA15Controler controler = new ZMCA15Controler();
        public ZMCA15()
        {
            InitializeComponent();
            FillGaugeData();       
        }

        private void FillGaugeData()
        {
            controler.GetGaugeData(gauge);
        }

    }

    public class ZMCA15Controler
    {
        DoubleCircleGauge gauge;
      
        public ZMCA15Controler()
        {

        }

        /// <summary>
        /// 调用服务ZMCA12.queryByIndex获得指标数据，然后填入指标盘
        /// </summary>
        /// <param name="gauge"></param>
        public void GetGaugeData(DoubleCircleGauge gauge)
        {
            this.gauge = gauge;
            gauge.gaugeTitle.Text = "安全";
            gauge.leftGaugeDescription.Text = "待整改隐患(个)";
            gauge.rightGaugeDescription.Text = "待处理三违(个)";
            gauge.leftGauge.Tag = "ZMCA71";
            gauge.rightGauge.Tag = "ZMCA83";

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA12");
            eiInfo.Set("method", "queryUnHandleRiskAndDeregulation");


            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getGaugeDataCompleted);
        }

        private void getGaugeDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIInfo eiInfo = e.EIInfo;
            EIBlock result = eiInfo.GetBlock("result");
            if (result != null && result.Rows.Count > 0)
            {
                foreach (var item in result.Rows)
                {
                    int nFlag = Common.GetIntValue(item["fdRiskCode"]);
                    if (nFlag == 0) //表示隐患数据
                    {
                        gauge.leftNeedle.Value = Common.GetIntValue(item["fdKeyId"]);
                    }
                    else if (nFlag == 1)//表示三违
                    {
                        gauge.rightNeedle.Value = Common.GetIntValue(item["fdKeyId"]);
                    }
                }
            }

            gauge.leftControler.IsReverse = true;
            gauge.rightControler.IsReverse = true;
        }    
    }
}